/*
 * This file contains all the javascript functions that use by
 * Syn message system plugin in Synergy digital asset management
 * system.
 * Create by: Weranga Kaluarachchi
 * Date: 18/04/2010
 */


/*
 * Confirm delete message
 * @return true or false
 */
function confirmMessageDelete() {
	// return if element does not exist
	if(document.getElementById('btnSynMsgDelete') == null) {
        return;
    }
    var isDelete = false;
    if(confirm('Do you really want to delete this message?')) {
    	isDelete = true;    
    }
    return isDelete;
}

/*
 * This method is using to toggle visibility of any div element.
 * @param element ID of the element wants toggle
 * @param object that trigger the function
 */
function toggleMessage(objID, me) { 
	//set visibility of edit project div
	if (document.getElementById(objID).style.display == "none") { 
	  	document.getElementById(objID).style.display="inline"; 
	  	me.innerHTML = "[hide]";
	}
	else {
		document.getElementById(objID).style.display="none"; 
	    me.innerHTML = "[show]";
    }
}

/*
 * Toggle visibility of selected message details
 * @param element ID of the element wants toggle
 * @param object that trigger the function
 */
function toggleOneMessage(objID) { 	
	//set visibility of edit project div
	if (document.getElementById(objID).style.display == "none") { 
	  	document.getElementById(objID).style.display="inline"; 
	}
	else {
		document.getElementById(objID).style.display="none"; 
   }
}



/*
 * Validate the maximum length of a component
 * @param	componenet	component that wants to validate
 * @param	int	maximum length 
 */
function textMessageLimit(field, maxlen) {
	if (field.value.length > maxlen) {
		alert('Message has exceeded the maximum length!');
		return;
	}

}

/*
 * Validate the project and the message before send to the server
 * @return true or false 
 */
function validateMessage() {
	if (document.getElementById('ldbProjects').value  == "No projects") {
		alert('There is no selected project!');
		return false;
	}
	else if(trimMessage(document.getElementById('txaMessage').value) == "") {
		alert('Message is blank!');
		return false;
	}

}


/*
 * Trim a string at the begining and at the end
 * @param	string which wants to trim
 * @return	string after trim 
 */
function trimMessage(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


